<template>
  <div class="operation-log">
    <h2>操作日志</h2>
    <el-table :data="logList" style="width: 100%">
      <el-table-column prop="operator" label="操作人" />
      <el-table-column prop="operation" label="操作类型" />
      <el-table-column prop="target" label="操作对象" />
      <el-table-column prop="details" label="操作详情" />
      <el-table-column prop="createdAt" label="操作时间">
        <template #default="scope">
          {{ new Date(scope.row.createdAt).toLocaleString() }}
        </template>
      </el-table-column>
    </el-table>
    
    <div class="pagination">
      <el-pagination
        v-model:current-page="currentPage"
        v-model:page-size="pageSize"
        :total="total"
        :page-sizes="[10, 20, 50, 100]"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'

const logList = ref([])
const currentPage = ref(1)
const pageSize = ref(10)
const total = ref(0)

// 获取日志列表
const fetchLogList = async () => {
  try {
    // TODO: 调用后端API获取日志列表
    // const response = await axios.get('/api/logs', {
    //   params: {
    //     page: currentPage.value,
    //     pageSize: pageSize.value
    //   }
    // })
    // logList.value = response.data.list
    // total.value = response.data.total
  } catch (error) {
    console.error('获取日志列表失败', error)
  }
}

// 处理页码变化
const handleCurrentChange = (val) => {
  currentPage.value = val
  fetchLogList()
}

// 处理每页条数变化
const handleSizeChange = (val) => {
  pageSize.value = val
  fetchLogList()
}

onMounted(() => {
  fetchLogList()
})
</script>

<style scoped>
.operation-log {
  padding: 20px;
}

.pagination {
  margin-top: 20px;
  display: flex;
  justify-content: flex-end;
}
</style> 